package com.wcx.application.controller;

import com.wcx.application.domian.SkillsBean;
import com.wcx.application.domian.SubindustriesBean;
import com.wcx.application.service.SkillsService;
import com.wcx.application.service.SubindustriesService;
import com.wcx.application.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/skills")
@CrossOrigin
public class SkillsController {

    @Autowired
    SkillsService skillsService;


    @GetMapping("/list")
    public Result getList() {
        System.out.println("---" + skillsService.getList());
        return Result.ok().data("list", skillsService.getList());
    }

    @PostMapping("/update")
    public Result update(@RequestBody SkillsBean skillsBean) {
        int i = skillsService.update(skillsBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }

    @PostMapping("/search")
    public Result search(@RequestBody  SkillsBean skillsBean) {
        return Result.ok().data("list", skillsService.searchList(skillsBean));
    }

    @PostMapping("/create")
    public Result create(@RequestBody SkillsBean skillsBean) {

        int i = skillsService.create(skillsBean);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }

    }

    @DeleteMapping("/delete")
    public Result delete(int id) {
        int i = skillsService.delete(id);
        if (i != 0) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }
}